import { service } from '@/config';

//首页得到banner
export function getBanner(data) {
    return $get('/subscribe/mini/serviceList',data)
}



const $get = (api, data = {}) => {
    return new Promise((resolve, reject) => {
        // 增强体验：加载中
        wx.showNavigationBarLoading()
        wx.showLoading({
            title:'',
            mask:true
        })
        wx.request({
            url: service.apiHost + api, 
            data: data,
            header: {
                'content-type': 'application/json', // 默认值
                'Cookie': 'JSESSIONID=CBC2F5B8BC89A4A949EA840DC7836ADF'
            },
            success: function(res) {
                //可添加白名单判断
                resolve(res)
            },
            fail: function(res) {
                reject(res)
            },
            complete: function(res) {
                // 隐藏加载提示
                wx.hideNavigationBarLoading()
                wx.hideLoading()
            }
        })
    })
}

const $post =  (api, data = {}) => {
    return new Promise((resolve, reject) => {
        // 增强体验：加载中
        wx.showNavigationBarLoading()
        wx.showLoading({
            title:'',
            mask:true
        })
        wx.request({
            url: service.apiHost + api, 
            data: data,
            header: {
                'content-type': 'application/x-www-form-urlencoded', // post
                'Cookie': 'JSESSIONID=CBC2F5B8BC89A4A949EA840DC7836ADF'
            },
            success: function(res) {
                resolve(res)
            },
            fail: function(res) {
                reject(res)
            },
            complete: function(res) {
                // 隐藏加载提示
                wx.hideNavigationBarLoading()
                wx.hideLoading()
            }
        })
    })
}
